// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    env: 'car-test-1jjya',
    traceUser: true
})
const db = cloud.database()
const carsdb = db.collection('cars')
exports.main = async (event, context) => {
  // 获取 OPENID 等微信上下文请使用 cloud.getWXContext()
const openId = cloud.getWXContext().OPENID

  console.log(openId)
  
  const result = await carsdb.where({       // 查询数据库中 openid字段
    openid:openId
  }).get()
  console.log(result.data)

  return result.data
}
